﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;

namespace YJKRevitAxisModule
{
	public class GridInfos
	{
		public GridInfos(GridInfos gridInfos)
		{
			this.m_Type = gridInfos.m_Type;
			this.m_ContainsPrefix = gridInfos.m_ContainsPrefix;
			this.m_MainGenericCode = gridInfos.m_MainGenericCode;
			this.m_SecondNumber = gridInfos.m_SecondNumber;
			this.m_Grid = gridInfos.m_Grid;
		}

		public GridInfos(_tagCharType type, string containsPrefix, int mainGenericCode, int secondNumber, Element grid)
		{
			this.m_Type = type;
			this.m_ContainsPrefix = containsPrefix;
			this.m_MainGenericCode = mainGenericCode;
			this.m_SecondNumber = secondNumber;
			this.m_Grid = grid;
		}

		public _tagCharType TheGridType
		{
			get
			{
				return this.m_Type;
			}
			set
			{
				this.m_Type = value;
			}
		}

		public string ContainsPrefix
		{
			get
			{
				return this.m_ContainsPrefix;
			}
			set
			{
				this.m_ContainsPrefix = value;
			}
		}

		public int MainGenericCode
		{
			get
			{
				return this.m_MainGenericCode;
			}
			set
			{
				this.m_MainGenericCode = value;
			}
		}

		public int SecondNumber
		{
			get
			{
				return this.m_SecondNumber;
			}
			set
			{
				this.m_SecondNumber = value;
			}
		}

		public bool IsMain
		{
			get
			{
				return this.m_Type == _tagCharType.CHARTYPE_ENGLISHCHAR_MAIN || this.m_Type == _tagCharType.CHARTYPE_NUMERAL_MAIN;
			}
		}

		public void Set(_tagCharType type, string containsPrefix, int mainGenericCode, int secondNumber)
		{
			this.m_Type = type;
			this.m_ContainsPrefix = containsPrefix;
			this.m_MainGenericCode = mainGenericCode;
			this.m_SecondNumber = secondNumber;
		}

		public string Name()
		{
			string text = this.ContainsPrefix;
			if (this.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_MAIN)
			{
				text += CharStringAndGenericCodeConvert.GenericCodeToEnglish(this.MainGenericCode);
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_SECOND)
			{
				text = text + this.SecondNumber.ToString() + "/";
				text += CharStringAndGenericCodeConvert.GenericCodeToEnglish(this.MainGenericCode);
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_REVERSE_SECOND)
			{
				text = text + this.SecondNumber.ToString() + "/";
				text += CharStringAndGenericCodeConvert.GenericCodeToEnglish(this.MainGenericCode);
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_NUMERAL_MAIN)
			{
				text += this.MainGenericCode.ToString();
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_NUMERAL_SECOND)
			{
				text = text + this.SecondNumber.ToString() + "/";
				text += this.MainGenericCode.ToString();
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_NUMERAL_REVERSE_SECOND)
			{
				text = text + this.SecondNumber.ToString() + "/";
				text += this.MainGenericCode.ToString();
			}
			return text;
		}

		public GridInfos GetNextGridInfos()
		{
			GridInfos gridInfos = null;
			if (this.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_MAIN || this.TheGridType == _tagCharType.CHARTYPE_NUMERAL_MAIN)
			{
				gridInfos = new GridInfos(this);
				gridInfos.MainGenericCode = CharStringAndGenericCodeConvert.GeneticCodeAddition(this.MainGenericCode, 1);
			}
			else if (this.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_SECOND || this.TheGridType == _tagCharType.CHARTYPE_NUMERAL_SECOND)
			{
				gridInfos = new GridInfos(this);
				GridInfos gridInfos2 = gridInfos;
				int secondNumber = gridInfos2.SecondNumber;
				gridInfos2.SecondNumber = secondNumber + 1;
			}
			return gridInfos;
		}

		public void SetName(string name, Autodesk.Revit.DB.Document doc)
		{
			if (this.m_Grid == null)
			{
				return;
			}
			if (this.m_Grid.GetType() == typeof(MultiSegmentGrid))
			{
				MultiSegmentGrid multiSegmentGrid = this.m_Grid as MultiSegmentGrid;
				multiSegmentGrid.Text = name;
				IEnumerator<ElementId> enumerator = multiSegmentGrid.GetGridIds().GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						ElementId id = enumerator.Current;
						RevitVersionFuncs.GetElement(doc, id).Name = name;
					}
					return;
				}
			}
			if (this.m_Grid.GetType() == typeof(Grid))
			{
				this.m_Grid.Name = name;
			}
		}

		public static int GridInfoCompare(GridInfos a, GridInfos b)
		{
			if (a.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_REVERSE_SECOND || a.TheGridType == _tagCharType.CHARTYPE_NUMERAL_REVERSE_SECOND)
			{
				if (b.TheGridType != _tagCharType.CHARTYPE_ENGLISHCHAR_REVERSE_SECOND && b.TheGridType != _tagCharType.CHARTYPE_NUMERAL_REVERSE_SECOND)
				{
					return -1;
				}
				if (a.SecondNumber > b.SecondNumber)
				{
					return -1;
				}
				if (a.SecondNumber < b.SecondNumber)
				{
					return 1;
				}
				return 0;
			}
			else if (a.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_SECOND || a.TheGridType == _tagCharType.CHARTYPE_NUMERAL_SECOND)
			{
				if (b.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_REVERSE_SECOND || b.TheGridType == _tagCharType.CHARTYPE_NUMERAL_REVERSE_SECOND)
				{
					return 1;
				}
				if (b.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_SECOND || b.TheGridType == _tagCharType.CHARTYPE_NUMERAL_SECOND)
				{
					if (a.m_MainGenericCode < b.m_MainGenericCode)
					{
						return -1;
					}
					if (a.m_MainGenericCode > b.m_MainGenericCode)
					{
						return 1;
					}
					if (a.SecondNumber < b.SecondNumber)
					{
						return -1;
					}
					if (a.SecondNumber > b.SecondNumber)
					{
						return 1;
					}
					return 0;
				}
				else
				{
					if (a.m_MainGenericCode < b.m_MainGenericCode)
					{
						return -1;
					}
					return 1;
				}
			}
			else
			{
				if (b.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_REVERSE_SECOND || b.TheGridType == _tagCharType.CHARTYPE_NUMERAL_REVERSE_SECOND)
				{
					return 1;
				}
				if (b.TheGridType == _tagCharType.CHARTYPE_ENGLISHCHAR_SECOND || b.TheGridType == _tagCharType.CHARTYPE_NUMERAL_SECOND)
				{
					if (a.m_MainGenericCode > b.m_MainGenericCode)
					{
						return 1;
					}
					return -1;
				}
				else
				{
					if (a.m_MainGenericCode < b.m_MainGenericCode)
					{
						return -1;
					}
					if (a.m_MainGenericCode > b.m_MainGenericCode)
					{
						return 1;
					}
					return 0;
				}
			}
		}

		private _tagCharType m_Type;

		private string m_ContainsPrefix;

		private int m_MainGenericCode;

		private int m_SecondNumber;

		private Element m_Grid;
	}
}
